﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

using Wiimote3DLibX;

namespace Wiimote3DTest
{
    public partial class Form1 : Form
    {
        public delegate void Input3DDelegate(object sender, Wiimote3DChangedEventArgs args);

        private Managed3D wiimanager;
        Thread mThread;

        public Form1()
        {
            InitializeComponent(); 
            wiimanager = new Managed3D(500);
            wiimanager.OnChanged3D += Wii3DChanged;
           //'wiimanager.Run();
            mThread = new Thread(new ThreadStart(wiimanager.Run));
            mThread.Start();
        }
        

        public void Wii3DChanged(object sender, Wiimote3DChangedEventArgs args)
        {
            this.Invoke(new Input3DDelegate(test), new Object[] { sender, args });
        }

        public void test(object sender, Wiimote3DChangedEventArgs args)
        {            
            //Console.WriteLine(args.Point3D);
            Point3Dx.Text = string.Format("X = {0}",args.Point3D.PointX);
            Point3Dy.Text = string.Format("Y = {0}",args.Point3D.PointY);
            Point3Dz.Text = string.Format("Z = {0}",args.Point3D.PointZ);            
        }

        protected override void OnClosed(EventArgs e)
        {
            mThread.Abort();
            wiimanager.Disconnect();
            base.OnClosed(e);
        }
    }
}
